*Recoding ZA3033

use "Data\ZA3033\ZA3033.dta" , clear

*Support for democracy
gen $idea_democracy			= V13

*Support for liberal democracy
gen $libdem_opposition			= V21
gen $libdem_freeopinion			= V19
gen $libdem_partyopportunity	= V22
gen $libdem_criticism			= V20							
gen $libdem_conflict			= V15							
gen $libdem_generalwill			= V23

*Satisfaction with democracy
gen $satisfaction_democracy		= V14

*define missing values
	*already defined 
*recode missing values 
	
*Standardize range from 0 to 1; higher values indicate higher support for democracy
*reverse scale if necessary and standardize
replace $satisfaction_democracy = (6-$satisfaction_democracy)/5 if !missing($satisfaction_democracy)


foreach var of varlist $libdem_opposition $libdem_freeopinion $libdem_partyopportunity {
	replace `var'	= (6-`var')/5 if !missing(`var')
}

*standardize remaining items 
replace $idea_democracy =  (6-$idea_democracy)/5  if !missing($idea_democracy)

foreach var of varlist $libdem_criticism $libdem_conflict $libdem_generalwill {
	replace `var'	=(`var'-1)/5 if !missing(`var')
}


*Sociodemographic Controls
gen		$gender 			= V153-1

gen 	$age				= V154

gen 	$education			= V155
replace $education 			= 0 if $education <= 3 					  // Schulabschluss ohne abgeschlossene Lehre, Schulabschluss mit abgeschlossener Lehre, Mittelschule = 0
replace $education 			= 1 if $education >  3					  // Abitur, Studium = 1

gen $eastwest 				= V3-1		


*Party ID
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
*Hier ist nur Partei-ID für Ostdeutsche vor der Wende vermerkt: V186

*Party Vote
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyvote_category		= 1 	if inlist(V185, 1, 3)
replace $partyvote_category	= 0 	if inlist(V185, 2, 4, 6)
replace $partyvote_category	= -1 	if inlist(V185, 5, 7)


*Meta variables
gen $dataset 					= "ZA3033"
gen $year 						= 1993
							 
*Gewicht
gen weight = V200

*check
tab $idea_democracy V13, m  //check

tab $libdem_opposition V21, m
tab $libdem_freeopinion V19, m
tab $libdem_partyopportunity V22, m
tab $libdem_criticism V20, m						
tab $libdem_conflict V15, m					
tab $libdem_generalwill V23, m	
tab $satisfaction_democracy V14, m	
tab $gender V153, m
tab $age V154, m
tab $education V155, m
tab $eastwest V3, m

*Save recode dataset
keep $idea_democracy $libdem_opposition	$libdem_freeopinion 					///
	$libdem_partyopportunity $libdem_criticism	$libdem_conflict 				///
	$libdem_generalwill $satisfaction_democracy $gender $age $education $eastwest $dataset $year  weight	$partyvote_category		
save ZA3033_recoded.dta, replace


